<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="对应 room 表的 id" prop="roomId">
        <el-input
          v-model="queryParams.roomId"
          placeholder="请输入对应 room 表的 id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房间区域" prop="area">
        <el-input
          v-model="queryParams.area"
          placeholder="请输入房间区域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="价格" prop="price">
        <el-input
          v-model="queryParams.price"
          placeholder="请输入价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分组名称" prop="groupName">
        <el-input
          v-model="queryParams.groupName"
          placeholder="请输入分组名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用途" prop="purpose">
        <el-input
          v-model="queryParams.purpose"
          placeholder="请输入用途"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预订人ID" prop="bookerId">
        <el-input
          v-model="queryParams.bookerId"
          placeholder="请输入预订人ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务人员ID" prop="serviceStaffId">
        <el-input
          v-model="queryParams.serviceStaffId"
          placeholder="请输入服务人员ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="DJ ID" prop="djId">
        <el-input
          v-model="queryParams.djId"
          placeholder="请输入DJ ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime">
        <el-date-picker clearable
          v-model="queryParams.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker clearable
          v-model="queryParams.endTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="预订人进场次数" prop="bookerEntryCount">
        <el-input
          v-model="queryParams.bookerEntryCount"
          placeholder="请输入预订人进场次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务人员进场次数" prop="serviceStaffEntryCount">
        <el-input
          v-model="queryParams.serviceStaffEntryCount"
          placeholder="请输入服务人员进场次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="DJ 进场次数" prop="djEntryCount">
        <el-input
          v-model="queryParams.djEntryCount"
          placeholder="请输入DJ 进场次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总金额" prop="totalAmount">
        <el-input
          v-model="queryParams.totalAmount"
          placeholder="请输入总金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="折扣" prop="discount">
        <el-input
          v-model="queryParams.discount"
          placeholder="请输入折扣"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务人员结算" prop="serviceStaffPayment">
        <el-input
          v-model="queryParams.serviceStaffPayment"
          placeholder="请输入服务人员结算"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="DJ 结算" prop="djPayment">
        <el-input
          v-model="queryParams.djPayment"
          placeholder="请输入DJ 结算"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务员结算" prop="salespersonPayment">
        <el-input
          v-model="queryParams.salespersonPayment"
          placeholder="请输入业务员结算"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段 aa" prop="aa">
        <el-input
          v-model="queryParams.aa"
          placeholder="请输入备用字段 aa"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段 bb" prop="bb">
        <el-input
          v-model="queryParams.bb"
          placeholder="请输入备用字段 bb"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段 cc" prop="cc">
        <el-input
          v-model="queryParams.cc"
          placeholder="请输入备用字段 cc"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="反馈" prop="feedback">
        <el-input
          v-model="queryParams.feedback"
          placeholder="请输入反馈"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段 ee" prop="ee">
        <el-input
          v-model="queryParams.ee"
          placeholder="请输入备用字段 ee"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段 ff" prop="ff">
        <el-input
          v-model="queryParams.ff"
          placeholder="请输入备用字段 ff"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="快照时间" prop="recordTime">
        <el-date-picker clearable
          v-model="queryParams.recordTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择快照时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:roomrecord:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:roomrecord:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:roomrecord:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:roomrecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="roomrecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键，快照记录ID" align="center" prop="id" />
      <el-table-column label="对应 room 表的 id" align="center" prop="roomId" />
      <el-table-column label="快照时间" align="center" prop="recordTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.recordTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="房间区域" align="center" prop="area" />
      <el-table-column label="价格" align="center" prop="price" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="分组名称" align="center" prop="groupName" />
      <el-table-column label="用途" align="center" prop="purpose" />
      <el-table-column label="预订人ID" align="center" prop="bookerId" />
      <el-table-column label="服务人员ID" align="center" prop="serviceStaffId" />
      <el-table-column label="DJ ID" align="center" prop="djId" />
<!--      <el-table-column label="开始时间" align="center" prop="startTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="结束时间" align="center" prop="endTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="预订人进场次数" align="center" prop="bookerEntryCount" />-->
<!--      <el-table-column label="服务人员进场次数" align="center" prop="serviceStaffEntryCount" />-->
<!--      <el-table-column label="DJ 进场次数" align="center" prop="djEntryCount" />-->
      <el-table-column label="总金额" align="center" prop="totalAmount" />
      <el-table-column label="折扣" align="center" prop="discount" />
      <el-table-column label="服务人员结算" align="center" prop="serviceStaffPayment" />
      <el-table-column label="DJ 结算" align="center" prop="djPayment" />
      <el-table-column label="业务员结算" align="center" prop="salespersonPayment" />
      <el-table-column label="备用字段 aa" align="center" prop="aa" />
      <el-table-column label="备用字段 bb" align="center" prop="bb" />
      <el-table-column label="备用字段 cc" align="center" prop="cc" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="反馈" align="center" prop="feedback" />
<!--      <el-table-column label="备用字段 ee" align="center" prop="ee" />-->
<!--      <el-table-column label="备用字段 ff" align="center" prop="ff" />-->

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:roomrecord:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:roomrecord:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改房间信息记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="对应 room 表的 id" prop="roomId">
          <el-input v-model="form.roomId" placeholder="请输入对应 room 表的 id" />
        </el-form-item>
        <el-form-item label="房间区域" prop="area">
          <el-input v-model="form.area" placeholder="请输入房间区域" />
        </el-form-item>
        <el-form-item label="价格" prop="price">
          <el-input v-model="form.price" placeholder="请输入价格" />
        </el-form-item>
        <el-form-item label="分组名称" prop="groupName">
          <el-input v-model="form.groupName" placeholder="请输入分组名称" />
        </el-form-item>
        <el-form-item label="用途" prop="purpose">
          <el-input v-model="form.purpose" placeholder="请输入用途" />
        </el-form-item>
        <el-form-item label="预订人ID" prop="bookerId">
          <el-input v-model="form.bookerId" placeholder="请输入预订人ID" />
        </el-form-item>
        <el-form-item label="服务人员ID" prop="serviceStaffId">
          <el-input v-model="form.serviceStaffId" placeholder="请输入服务人员ID" />
        </el-form-item>
        <el-form-item label="DJ ID" prop="djId">
          <el-input v-model="form.djId" placeholder="请输入DJ ID" />
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <el-date-picker clearable
            v-model="form.startTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-date-picker clearable
            v-model="form.endTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预订人进场次数" prop="bookerEntryCount">
          <el-input v-model="form.bookerEntryCount" placeholder="请输入预订人进场次数" />
        </el-form-item>
        <el-form-item label="服务人员进场次数" prop="serviceStaffEntryCount">
          <el-input v-model="form.serviceStaffEntryCount" placeholder="请输入服务人员进场次数" />
        </el-form-item>
        <el-form-item label="DJ 进场次数" prop="djEntryCount">
          <el-input v-model="form.djEntryCount" placeholder="请输入DJ 进场次数" />
        </el-form-item>
        <el-form-item label="总金额" prop="totalAmount">
          <el-input v-model="form.totalAmount" placeholder="请输入总金额" />
        </el-form-item>
        <el-form-item label="折扣" prop="discount">
          <el-input v-model="form.discount" placeholder="请输入折扣" />
        </el-form-item>
        <el-form-item label="服务人员结算" prop="serviceStaffPayment">
          <el-input v-model="form.serviceStaffPayment" placeholder="请输入服务人员结算" />
        </el-form-item>
        <el-form-item label="DJ 结算" prop="djPayment">
          <el-input v-model="form.djPayment" placeholder="请输入DJ 结算" />
        </el-form-item>
        <el-form-item label="业务员结算" prop="salespersonPayment">
          <el-input v-model="form.salespersonPayment" placeholder="请输入业务员结算" />
        </el-form-item>
        <el-form-item label="备用字段 aa" prop="aa">
          <el-input v-model="form.aa" placeholder="请输入备用字段 aa" />
        </el-form-item>
        <el-form-item label="备用字段 bb" prop="bb">
          <el-input v-model="form.bb" placeholder="请输入备用字段 bb" />
        </el-form-item>
        <el-form-item label="备用字段 cc" prop="cc">
          <el-input v-model="form.cc" placeholder="请输入备用字段 cc" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="反馈" prop="feedback">
          <el-input v-model="form.feedback" placeholder="请输入反馈" />
        </el-form-item>
        <el-form-item label="备用字段 ee" prop="ee">
          <el-input v-model="form.ee" placeholder="请输入备用字段 ee" />
        </el-form-item>
        <el-form-item label="备用字段 ff" prop="ff">
          <el-input v-model="form.ff" placeholder="请输入备用字段 ff" />
        </el-form-item>
        <el-form-item label="快照时间" prop="recordTime">
          <el-date-picker clearable
            v-model="form.recordTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择快照时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRoomrecord, getRoomrecord, delRoomrecord, addRoomrecord, updateRoomrecord } from "@/api/system/roomrecord";

export default {
  name: "Roomrecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 房间信息记录表格数据
      roomrecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roomId: null,
        area: null,
        price: null,
        status: null,
        groupName: null,
        purpose: null,
        bookerId: null,
        serviceStaffId: null,
        djId: null,
        startTime: null,
        endTime: null,
        bookerEntryCount: null,
        serviceStaffEntryCount: null,
        djEntryCount: null,
        totalAmount: null,
        discount: null,
        serviceStaffPayment: null,
        djPayment: null,
        salespersonPayment: null,
        aa: null,
        bb: null,
        cc: null,
        feedback: null,
        ee: null,
        ff: null,
        recordTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        roomId: [
          { required: true, message: "对应 room 表的 id不能为空", trigger: "blur" }
        ],
        recordTime: [
          { required: true, message: "快照时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询房间信息记录列表 */
    getList() {
      this.loading = true;
      listRoomrecord(this.queryParams).then(response => {
        this.roomrecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        roomId: null,
        area: null,
        price: null,
        status: null,
        groupName: null,
        purpose: null,
        bookerId: null,
        serviceStaffId: null,
        djId: null,
        startTime: null,
        endTime: null,
        bookerEntryCount: null,
        serviceStaffEntryCount: null,
        djEntryCount: null,
        totalAmount: null,
        discount: null,
        serviceStaffPayment: null,
        djPayment: null,
        salespersonPayment: null,
        aa: null,
        bb: null,
        cc: null,
        remark: null,
        feedback: null,
        ee: null,
        ff: null,
        recordTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加房间信息记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRoomrecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改房间信息记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRoomrecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRoomrecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除房间信息记录编号为"' + ids + '"的数据项？').then(function() {
        return delRoomrecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/roomrecord/export', {
        ...this.queryParams
      }, `roomrecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
